package com.ceair.flight.refund.util;


import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 * 
 * @author wanghaipeng
 * 2016-04-29
 *
 */
public class ConfigUtil extends PropertyPlaceholderConfigurer  {
    private static Map<String, Object> ctxPropertiesMap;
    
    static{
    	
    }
	@Override 
    protected void processProperties( 
            ConfigurableListableBeanFactory beanFactoryToProcess, 
            Properties props) throws BeansException { 
        super.processProperties(beanFactoryToProcess, props); 
        ctxPropertiesMap = new HashMap<String, Object>(); 
        for (Object key : props.keySet()) { 
            String keyStr = key.toString(); 
            String value = props.getProperty(keyStr); 
            ctxPropertiesMap.put(keyStr, value); 
        }
    } 
	
	public static int getIntValue(String key){
		return ctxPropertiesMap.get(key)==null?0:Integer.parseInt(ctxPropertiesMap.get(key).toString());
	}
	public static double getDoubleValue(String key){
		return ctxPropertiesMap.get(key)==null?0d:Double.parseDouble(ctxPropertiesMap.get(key).toString());
	}
	public static float getFloatValue(String key){
		return ctxPropertiesMap.get(key)==null?0f:Float.parseFloat(ctxPropertiesMap.get(key).toString());
	}
	public static String getStringValue(String key){
		return ctxPropertiesMap.get(key)==null?"":ctxPropertiesMap.get(key).toString();
	}
	
	public static String[] getStringArrayValues(String key){
		return ctxPropertiesMap.get(key)==null?new String[0]:ctxPropertiesMap.get(key).toString().split(",");
	}
}
